package com.oocl.euc.core.maintenance.model;

import com.oocl.euc.audit.AuditEntity;

import javax.persistence.*;

@Entity
@Table(name = "PCRS_ROLE_AUTH")
@SequenceGenerator(name = "SEQUENCE_GENERATOR", sequenceName = "ROLE_AUTH_SEQUENCE", allocationSize = 1)
public class RoleAuth extends AuditEntity {

    @ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "SUPPORT_GROUP_ID", referencedColumnName = "ID")
    private SupportGroup supportGroup;

    @ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "STAFF_ID", referencedColumnName = "STAFF_ID")
    private Users users;

    public SupportGroup getSupportGroup() {
        return supportGroup;
    }

    public void setSupportGroup(SupportGroup supportGroup) {
        this.supportGroup = supportGroup;
    }

    @Transient
    public String getUserName() {
        if (this.supportGroup != null) {
            return this.supportGroup.getGroupName();
        }
        if (this.users != null) {
            return this.users.getDomainId();
        }
        return "";
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    @Transient
    public String getUserDesc() {
        if (this.supportGroup != null) {
            return this.supportGroup.getGroupDesc();
        }
        if (this.users != null) {
            return this.users.getDisplayName();
        }
        return "";
    }
}
